// pages/oa/approval/myoadetails.js
var api = require("../../../utils/api.js");
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    examine_type: "",
    id: "",
    examineInfo: {},
    caseInfos: {},
    oaApplyInfos: {},
    statusStyle: ["success", "gray", "blue", "red"],
    uid: "",
    stateId: "",
    oaId: "",
    orgid: "",
    userName: "",
    index: [0, 0],
    cost: ['', '公函', '介绍信', '律师函', '法律意见书', '非诉'],
    refund: ['', '转账支票', '电汇', '网银', 'POS机', '现金'],
    invoiceType: ['', '增值税专用发票', '增值税普通发票', '普通机打发票'],
    settlemode: ['判决', '撤诉', '终结', '调解', '移送', '不予受理', '驳回起诉', '其它'],
    nameText: ['', '撤诉事由', '终结事由', '', '受指定或移送法院', '不予受理原因', '驳回原因', '解除委托原因', ''],
    searchName: "",
    case_id: "", //案件id
    contract_number: "", //案件号
    plaintiff_collector: "", //委托人
    processPersonList: [],//签核人
    accountInfosList: [{}], //抄送人
    osApprovalsListSize: "",
    userName: "",
    finalState: ["", "", ""],
    userIds: [], //新增加的抄送人
    user_person_id: wx.getStorageSync('userId'), //领用人
    //附件照片
    fileUrlList: [{}],
    //图片附件
    imgUrls: [""],
    small_examine_type: "",//申请小类型 用于借阅申请
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: "审批详情"
    });
    var caseId = options.caseId;
    var stateId = "";
    var oaId = options.oaId;
    /**审批时需要 */
    var uid = wx.getStorageSync('userId');
    var orgid = wx.getStorageSync('companyId');
    var userName = wx.getStorageSync('name');
    that.setData({
      caseId: caseId,
      stateId: stateId,
      oaId: oaId,
      uid: uid,
      orgid: orgid,
      userName: userName,
    });
    that.getexamineInfo();


  },
  //跳转申请详情
  showOaDetail: function (e) {
    var idx = e.currentTarget.dataset.id;
    var examinetype = e.currentTarget.dataset.examinetype;
    var toPageName = "";
    var typeid = "";
    var small_examine_type = this.data.small_examine_type;
    if (examinetype == '1') {
      toPageName = "print";
    } else if (examinetype == "2") {
      toPageName = "invoice";
    } else if (examinetype == "3") {
      toPageName = "cost";
    } else if (examinetype == "4") {
      toPageName = "refund";
    } else if (examinetype == "5") {
      toPageName = "settle";
    } else if (examinetype == "6") {
      toPageName = "setcase";
    } else if (examinetype == "11") {
      toPageName = "purchase";
    } else if (examinetype == 10) {
      toPageName = "papers"
      typeid = 4;
    } else if (examinetype == 7) {
      toPageName = "papers"
      if (small_examine_type == 1) {
        typeid = 0;
      } else if (small_examine_type == 2) {
        typeid = 1;
      } else if (small_examine_type == 3) {
        typeid = 2;
      } else if (small_examine_type == 4) {
        typeid = 3;
      }

    } else if (examinetype == 13) {
      toPageName = "maintain"
      typeid = 11;
    } else if (examinetype == 14) {
      toPageName = "maintain"
      typeid = 12;
    } else if (examinetype == 12) {
      toPageName = "maintain"
      typeid = 13;
    } else if (examinetype == 9) {
      toPageName = "leaveoffice"
      typeid = 14;
    } else if (examinetype == 15) {
      toPageName = "leaveoffice"
      typeid = 8;
    }
    wx.navigateTo({
      url: '../application/' + toPageName + '?oaId=' + idx + "&typeid=" + typeid
    });
  },
  getexamineInfo: function () {
    var that = this;
    wx.showLoading({
      title: "正在加载中...",
    })
    api.fetchApi2("oaApproval/queryExamine?examineType=" + that.data.examine_type + "&oaId=" + that.data.oaId, {
    }, "POST").then(res => {
      wx.hideLoading();
      var datas = res.data;
      var oaApplyInfos = datas.oaApplyInfos;
      var is_examine = oaApplyInfos.is_examine;


      if (oaApplyInfos["create_time"] != null && oaApplyInfos["create_time"] != undefined && oaApplyInfos["create_time"] != "") {
        oaApplyInfos["create_time"] = util.formatTimeDay(new Date(oaApplyInfos["create_time"]));
      }
      if (oaApplyInfos["refund_time"] != "" && oaApplyInfos["refund_time"] != undefined && oaApplyInfos["refund_time"] != null) {
        oaApplyInfos["refund_time"] = util.formatTimeDay(new Date(oaApplyInfos["refund_time"]));
      }
      if (oaApplyInfos["printing_time"] != "" && oaApplyInfos["printing_time"] != undefined && oaApplyInfos["printing_time"] != null) {
        oaApplyInfos["printing_time"] = util.formatTimeDay(new Date(oaApplyInfos["printing_time"]));
      }
      var processPersonList = datas.processPersonList;

      that.setData({
        caseInfos: datas.caseInfos,
        oaApplyInfos: oaApplyInfos,
        processPersonList: datas.processPersonList,
        accountInfosList: datas.accountInfosList,
        small_examine_type: datas.oaApplyInfos.small_examine_type
      })

      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    });
  },
  formSubmit: function (e) {
    var that = this;
    var remark = e.detail.value.remark;
    var is_examine = e.detail.value.is_examine;
    api.fetchApi2("oaApproval/examineOaApply", {
      ids: that.data.caseId,
      "type": is_examine,
      examine_type: that.data.examine_type,
      remark: remark,
      uid: that.data.uid,
      orgid: that.data.orgid,
      userName: that.data.userName,
    }, "POST").then(res => {
      if (res.data == "success") {



      } else {
        wx.showToast({
          title: '数据加载失败',
          icon: 'none'
        })
      }
    });
  },
  backPage: function () {
    wx.navigateBack({ changed: true });//返回上一页
  },
  //案件详情
  reditCaseInfo: function (option) {
    var id = option.currentTarget.dataset.caseid;
    wx.navigateTo({
      url: "../../case/management/detail?case_id=" + id    //案件收支详情
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})